package demo03;

import java.util.Arrays;
import java.util.Scanner;

public class ShellSort {
    public static void main(String[] args) {
        ShellSort();
    }

    public static void ShellSort() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] arr = new int[n];
        for(int i = 0;i < n;i++){
            arr[i] = sc.nextInt();
        }
        int gap = arr.length;
        while(gap > 1){
            gap /= 2;
            for(int i = gap;i < arr.length;i++){
                int tmp = arr[i];
                int j = i - gap;
                for(;j >= 0;j -= gap){
                    if(arr[j] > tmp){
                        arr[j + gap] = arr[j];
                    } else{
                        break;
                    }
                }
                arr[j + gap] = tmp;
            }
        }
        System.out.println(Arrays.toString(arr));
    }
}
